#chmod 777

# 当前项目名字，需要修改！
PROJECT_NAME='YYModel'

# 编译工程
BINARY_NAME="${PROJECT_NAME}"

BUILD_SWIFT=true

INSTALL_DIR="./Pod/products"
rm -fr ${INSTALL_DIR}
mkdir -p $INSTALL_DIR
WRK_DIR=build

BUILD_PATH=${WRK_DIR}

DEVICE_DIR=${BUILD_PATH}/Release-iphoneos/${BINARY_NAME}.framework
SIMULATOR_DIR=${BUILD_PATH}/Release-iphonesimulator/${BINARY_NAME}.framework
RE_OS="Release-iphoneos"
RE_SIMULATOR="Release-iphonesimulator"

xcodebuild -project "${PROJECT_NAME}.xcodeproj" \
           -scheme "${BINARY_NAME}" \
           CONFIGURATION_BUILD_DIR="${WRK_DIR}/${RE_SIMULATOR}" \
           LIBRARY_SEARCH_PATHS="./Pods/build/${RE_SIMULATOR}" \
           -sdk iphonesimulator clean build 
xcodebuild -project "${PROJECT_NAME}.xcodeproj" \
           -scheme "${BINARY_NAME}" \
           CONFIGURATION_BUILD_DIR="${WRK_DIR}/${RE_OS}" \
           LIBRARY_SEARCH_PATHS="./Pods/build/${RE_OS}" \
           -sdk iphoneos clean build



echo " It is a test======="
echo ${DEVICE_DIR}
echo $SIMULATOR_DIR

cp -rp "${DEVICE_DIR}" "${INSTALL_DIR}/"

lipo -create "${DEVICE_DIR}/${BINARY_NAME}" "${SIMULATOR_DIR}/${BINARY_NAME}" -output "${INSTALL_DIR}/${BINARY_NAME}.framework/${BINARY_NAME}"

cp -rp ${SIMULATOR_DIR}/Modules/${BINARY_NAME}.swiftmodule/*.{swiftmodule,swiftdoc,swiftinterface} "$INSTALL_DIR/$BINARY_NAME.framework/Modules/$BINARY_NAME.swiftmodule"
cp -rp ${SIMULATOR_DIR}/Modules/${BINARY_NAME}.swiftmodule/Project/*.swiftsourceinfo "$INSTALL_DIR/$BINARY_NAME.framework/Modules/$BINARY_NAME.swiftmodule/Project"


fileSwift="../../Pod/Products/${PROJECT_NAME}.framework/Headers/${PROJECT_NAME}-Swift.h"

str3="#if defined(__x86_64__) && __x86_64__ || (__arm64__) && __arm64__"
#在 项目名.framework/Headers/项目名-Swift.h里面修改内容内容

str1="#if 0"
str2="#elif defined(__arm64__) && __arm64__"
str3="#if defined(__x86_64__) && __x86_64__ || (__arm64__) && __arm64__"
#修改
#查找#if 0替换成空
sed -i '' 's/#if 0//g' $fileSwift
#查找#elif defined(__arm64__) && __arm64__替换成空
sed -i '' 's/#elif defined(__arm64__) && __arm64__//g' $fileSwift
#在1第一行添加字符串#if defined( __x86_64__ ) && __x86_64__ || (__arm64__) && __arm64__
sed -i '' "1 a\\ $str3" $fileSwift

#rm -r "${WRK_DIR}"




